<template>
  <el-card>
    <div slot="header" class="me-name">
            <i class="iconfont icon-liuyan"></i>
            <span>路友留言</span>
    </div>
    <el-row v-for="(message, index) in dataList" :key="index" class="lmess-main">
      <el-tooltip class="item" effect="dark" :content=message.content placement="right">
        <div class="leav-item"><p style="width: 100%;"><span style="color: #000;float:left;width:23%;">{{handleName(message.userName)}}：</span>
        <span style="width:77%;float:left;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">{{message.content}}</span></p>
        <span style="width: 25%; text-align:right;">{{message.date}}</span></div>
    </el-tooltip>
    </el-row>
  </el-card>
</template>

<script>

import {getAllMess} from '../../api/mess'

export default {
  name: 'Lmess',
  data() {
    return {
      dataList: []
    }
  },
  created(){
    this.getMess();
  },
  methods: {
    getMess(){  // 获取当前文章评论
      let that = this
      getAllMess().then(res => {
          let newMess;
          newMess = res.data
          // this.dataList.length = newCommtent
          this.dataList = newMess
      })
    },
    handleName(name){
      if(name.length > 2){
        let userName = name.substring(0, 2);
        return userName + ' ...'
      }else{
        return name;
      }
    }
  }
}

</script>

<style scoped>
el-card {
  width: 100%;
  box-shadow: 2px 4px 4px 2px rgba(0, 0, 0, .2);
}
.el-card {
  padding: 0 0 20px 0;
  /* height: 450px; */
}
.el-col{
    animation-duration: 2s;
    animation-delay: 1s;
    animation-iteration-count: 1;
}
.icon-liuyan {
  color: #00ff08;
  font-size: 20px;
}
.me-name span{
  font-size: 18px;
  font-weight: bolder;
}
.lmess-main {
  width: 100%;
}
.lmess-main span {
  font-size: 12px;
}
.leav-row {
  width: 100%;
  display: block;
}
.leav-item {
  display: flex;
  margin: 2px 0;
  color: #9f9f9f;
  height: 20px;
  line-height: 20px;
}
.leav-item:hover{
  background-color: #dcdcdc;
}
</style>